package com.zone.vehicle.superapp.bean;

import com.saicmotor.pay.db.entity.Pay;
import com.zone.lib.download.db.entity.Download;
import com.zone.sdk.module.appstore.base.StoreUtils;
import com.zone.sdk.module.appstore.entity.AppDetailEntity;
import com.zone.sdk.module.appstore.entity.AppEntity;
import com.zone.sdk.module.appstore.entity.LabelItem;
import com.zone.sdk.module.appstore.entity.ResourceItem;
import com.zone.vehicle.sdk.module.superapp.entity.AppUpdateEntity;

import java.util.LinkedList;
import java.util.List;

import lombok.Data;

/**
 * @Author: pkqlqx
 * @CreateDate: 2022/1/2 19:42
 * @Description:
 */
@Data
public class AppBean extends AppDetailEntity {

    private static final long serialVersionUID = -7763109915960493407L;

    private Download download;

    private AppUpdateEntity updateEntity;

    private Pay pay;

    public void buildFromEntry(AppEntity appEntity) {
        setAppType(appEntity.getAppType());
        setCode(appEntity.getCode());
        setVehicleType(appEntity.getAdapterModel());
        setDownloadCount(String.valueOf(appEntity.getDownCount()));
        setDetailDesc(appEntity.getDesc());
        setDescription(appEntity.getDescription());
        setDeveloper(appEntity.getDeveloper());
        setSelfRecommendDescription(appEntity.getDeveloperWord());
        setIconUrl(appEntity.getIcon());
//        setImages(appEntity.getImages());

        ResourceItem item = new ResourceItem();
        item.setResourceId(StoreUtils.RESOURCE_ID_PREVIEW);
        item.setResourceType(StoreUtils.RESOURCE_TYPE_PIC);
        item.setResourceUrl(appEntity.getUrl());
        addResourceItem(item);

        String[] labels = appEntity.getLabels().split(",");
        List<LabelItem> labelItemList = new LinkedList<>();
        for (String l : labels) {
            LabelItem labelItem = new LabelItem();
            labelItem.setLableName(l);
            labelItemList.add(labelItem);
        }
        setLabelList(labelItemList);
//        setLabels(appEntity.getLabels());
//        setOldVersion(appEntity.getOldVersion());
//        setNewVersion(appEntity.getNewVersion());
        setVersion(appEntity.getNewVersion());
//        setUpdateDesc(appEntity.getUpdateDesc());
        setProductPrice(appEntity.getProductPrice());
    }

    public AppBean build(AppDetailEntity appEntity) {
        copy(appEntity);
        return this;
    }
}
